<template>
	<view :class="['page',{'iphoneX':isIphoneX}]">
		<template v-if="isLogin">
			<template v-if="loadingState.default">
				<loading :loadingState="loadingState"></loading>
			</template>

			<template v-else>
				<view class="body">

					<!-- 每日评价 -->
					<template v-if="type=='day'">
						<view class="hd-title">药剂评价</view>
						<view class="detail-wrap m-b2">
							<view class="item">
								<view class="title">
									<text>药剂三证是否齐全：</text>
									<image v-if="detail.datainfo.pesticide_is_egal==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
							<view class="item">
								
								<view class="title">
									<text>药剂防治对象登记为红火蚁：</text>
									<image v-if="detail.datainfo.pesticide_is_ant==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
							<view class="item">
								
								<view class="title">
									<text>药剂在使用期限内：</text>
									<image v-if="detail.datainfo.pesticide_is_valid==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
							<view class="item">
								
								<view class="title">
									<text>有药剂出入库登记管理：</text>
									<image v-if="detail.datainfo.pesticide_is_register==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
						</view>

						<view class="hd-title">作业评价</view>
						<view class="detail-wrap m-b2">
							<view class="item">
								<view class="title">
									<text>工具配备.安全防护评级：</text>
									<text v-if="detail.datainfo.tool_rank==1" class="f-green">优</text>
									<text v-if="detail.datainfo.tool_rank==2" class="f-blue">良</text>
									<text v-if="detail.datainfo.tool_rank==3" class="f-red">差</text>
								</view>
							</view>
							<view class="item">
								
								<view class="title">
									<text>药施药是否规范：</text>
									<image v-if="detail.datainfo.work_is_standard==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
							<view class="item">
								
								<view class="title">
									<text>完整记录施药时间、施药剂量、防治面积：</text>
									<image v-if="detail.datainfo.work_is_record==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
							<view class="item">
								
								<view class="title">
									<text>上传防控现场照片：</text>
									<image v-if="detail.datainfo.photo_is_upload==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
						</view>
						<!-- 药剂/作业照片 -->
						<view class="hd-title">药剂/作业照片</view>
						<view class="form-wrap m-b2">
							<view class="upload-pic-item">
								<view class="form-upload-pic">
									<template>
										<view class="img-item" v-for="(item,index) in detail.files" :key="index">
											<image src="@/static/images/filter_bg.png" mode="widthFix">
												<!-- 占位 -->
											</image>
											<view class="img-wrap" @click="previewPic(index,2)">
												<image class="img" :src="img_path+item.file_path" mode="widthFix">
												</image>
											</view>
										</view>
									</template>
								</view>
							</view>
						</view>

						<view class="form-wrap m-b2">
							<view class="form-textarea-item">
								<view class="label a-t">监理意见</view>
								<view class="form-textarea">
									<textarea class="inp-textarea" auto-height="true" v-model="detail.datainfo.content" disabled
										placeholder="监理意见" maxlength="-1"></textarea>
								</view>
							</view>
						</view>

						<view class="hd-title">总体评价</view>
						<view class="detail-wrap m-b2">
							<view class="item">
								<view class="title">
									<text>今日作业是否合规：</text>
									<image v-if="detail.datainfo.work_is_pass==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
						</view>
					</template>

						
					<!-- 阶段评价 --> 
					<template v-if="type=='stage'">
						<view class="hd-title">药剂评价</view>
						<view class="detail-wrap m-b2">
							<view class="item">
								<view class="title">
									<text>药剂三证是否齐全：</text>
									<image v-if="detail.datainfo.pesticide_is_egal==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
							<view class="item">
								
								<view class="title">
									<text>药剂防治对象登记为红火蚁：</text>
									<image v-if="detail.datainfo.pesticide_is_ant==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
							<view class="item">
								
								<view class="title">
									<text>药剂在使用期限内：</text>
									<image v-if="detail.datainfo.pesticide_is_valid==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
							<view class="item"> 
								<view class="title">
									<text>有药剂出入库登记管理：</text>
									<image v-if="detail.datainfo.pesticide_is_register==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
						</view>
						
						<view class="hd-title">作业评价</view>
						<view class="detail-wrap m-b2">
							<view class="item">
								<view class="title">
									<text>防治工作在红火蚁监测完成后的7个工作日内开展：</text>
									<image v-if="detail.datainfo.work_is_inweek==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
							<view class="item"> 
								<view class="title">
									<text>施药范围覆盖合同规定的区域及面积：</text>
									<image v-if="detail.datainfo.work_is_inarea==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
							<view class="item"> 
								<view class="title">
									<text>该阶段全面施药在合同规定时间内完成：</text>
									<image v-if="detail.datainfo.work_is_ontime==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
							<view class="item">
								
								<view class="title">
									<text>施药开始日期：{{detail.datainfo.begin_time}}</text> 
								</view>
							</view>
							<view class="item">
								<view class="title">
									<text>施药结束日期：{{detail.datainfo.end_time}}</text> 
								</view>
							</view>
							<view class="item"> 
								<view class="title">
									<text>实际作业用时：{{day}}天</text> 
								</view>
							</view>
							<view class="item">
								<view class="title">
									<text>工具配备、安全防护评级：</text>
									<text v-if="detail.datainfo.tool_rank==1" class="f-green">优</text>
									<text v-if="detail.datainfo.tool_rank==2" class="f-blue">良</text>
									<text v-if="detail.datainfo.tool_rank==3" class="f-red">差</text> 
								</view>
							</view>
							<view class="item"> 
								<view class="title">
									<text>施工前对作业人员进行不少于1次的工作培训：</text>
									<image v-if="detail.datainfo.worker_is_train==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
							<view class="item"> 
								<view class="title">
									<text>施药是否规范：</text>
									<image v-if="detail.datainfo.work_is_standard==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
							<view class="item"> 
								<view class="title">
									<text>完整记录施药时间、施药剂量、防治面积：</text>
									<image v-if="detail.datainfo.work_is_record==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
							<view class="item">
								<view class="title">
									<text>上传防控现场照片：</text>
									<image v-if="detail.datainfo.photo_is_upload==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
						</view>
						<!-- 药剂/作业照片 -->
						<view class="hd-title">药剂/作业照片</view>
						<view class="form-wrap m-b2">
							<view class="upload-pic-item">
								<view class="form-upload-pic">
									<template>
										<view class="img-item" v-for="(item,index) in detail.files" :key="index">
											<image src="@/static/images/filter_bg.png" mode="widthFix">
												<!-- 占位 -->
											</image>
											<view class="img-wrap" @click="previewPic(index)">
												<image class="img" :src="img_path+item.file_path" mode="widthFix">
												</image>
											</view>
										</view>
									</template>
								</view>
							</view>
						</view>
						
						<view class="hd-title">防效评价</view>
						<view class="detail-wrap m-b2">
							<view class="item">
								<view class="title">
									<text>防控前总评等级：{{detail.datainfo.before_relevel}}级</text> 
								</view>
							</view>
							<view class="item"> 
								<view class="title">
									<text>防控后总评等级：{{detail.datainfo.after_relevel}}级</text> 
								</view>
							</view>
							<view class="item"> 
								<view class="title">
									<text>活蚁巢减退率：{{detail.datainfo.nest_decline_rate}}%</text> 
								</view>
							</view>
							<view class="item"> 
								<view class="title">
									<text>工蚁减退率：{{detail.datainfo.ant_decline_rate}}%</text> 
								</view>
							</view>							
						</view>
						<view class="form-wrap m-b2">
							<view class="form-textarea-item">
								<view class="label a-t">监理意见</view>
								<view class="form-textarea">
									<textarea class="inp-textarea" v-model="detail.datainfo.content" disabled
										placeholder="监理意见" maxlength="-1"></textarea>
								</view>
							</view>
						</view>
						
						
						<view class="hd-title">总体评价</view>
						<view class="detail-wrap m-b2">
							<view class="item">
								<view class="title">
									<text>达到项目阶段目标：</text>
									<image v-if="detail.datainfo.work_is_pass==1" src="@/static/images/y.png"
										mode="widthFix"></image>
									<image v-else src="@/static/images/x.png" mode="widthFix"></image>
								</view>
							</view>
							<view class="item">
								<view class="title">
									<text>评价时间：{{detail.datainfo.create_time}}</text> 
								</view>
							</view>
						</view>
						
					
						 
					</template>
					
					
					 
				</view>

				<!-- 底部 -->
				<view class="footer">
					<view class="fix-wrap bottom">
						<view class="form-lay-btn" @click="del">删除评价</view>
					</view>
				</view>

			</template>



		</template>
	</view>
</template>

<script>
	import {
		dateFormat,
		uploadImage,
		previewImage,
		uploadToServe
	} from '@/common/util.js'
	import {
		img_path
	} from '@/config.js'
	import loading from '@/components/loading-more.vue'
	import empty from '@/components/empty.vue'
	export default {
		name: 'name',
		data() {
			return {
				isLogin: true,
				isIphoneX: getApp().globalData.isIphoneX,
				userInfo: uni.getStorageSync('userInfo'),
				isStop: true,
				type: '',
				loadingState: {
					default: true,
				},
				detail: {},
				params: {
					id: '',
					pesticide_is_egal: '1',
					pesticide_is_ant: '1',
					pesticide_is_valid: 1,
					pesticide_is_register: 1,
					tool_rank: 1,
					work_is_standard: 1,
					work_is_record: 1,
					photo_is_upload: 1,
					work_is_pass: 1,
					content: '',
					type: 1,
					p_id: '',
					files: [],
					files_1: [], // 药剂照片
					files_2: [] // 作业照片
				},
				img_path: img_path
			}


		},
		async onLoad(params) {
			this.type = params.type;
			this.params.id = params.id;
			this.params.type = params.datatype,
				this.isLogin = await this.$loginState('check');

			if (this.type == 'day') {
				uni.setNavigationBarTitle({
					title: "每日评价数据"
				})
			} else if (this.type == 'stage') {
				uni.setNavigationBarTitle({
					title: "阶段评价数据"
				})
			}

			if (this.isLogin) {
				this.getJlproDatainfo();
			}
		},
		async onShow() {

		},
		methods: {

			getJlproDatainfo: async function() {
				let res = await this.$api.pro_api.jlprodatainfo({
					id: this.params.id,
				}) 
				if (res.data.ret == 0) {
					this.loadingState.default = false;
					this.detail = res.data.data;
				} else {
					this.loadingState.default = false;
				}
			},
			
			// 预览图片
			previewPic: function(index) {
				let _this = this;
				let preview_data = [];
				this.detail.files.forEach(item => {
					preview_data.push(this.img_path+item.file_path);
				})
			
				previewImage({
					data: preview_data,
					index: index
				})
			},

			del: function() {
				let _this = this;
				uni.showModal({
					content: "确定删除该评价吗？",
					async success(res) {
						if (res.confirm) {
							let del_res = await _this.$api.pro_api.jlprodeletedata({
								id: _this.params.id,
								status: 0
							})
							if (del_res.data.ret == 0) {
								_this.$store.commit('UPDATE_PJ_INIT', false); // 数据更新
								_this.$store.commit('UPDATE_PJ_LIST', true); // 数据更新
								uni.showToast({
									icon: 'success',
									mask: true,
									title: '删除成功',
									duration: 1000,
									success() {
										setTimeout(() => {
											uni.navigateBack({
												delta: 1
											})
										}, 1000)
									}

								})
							} else {
								uni.showToast({
									icon: 'none',
									image: '../../static/images/error.png',
									mask: true,
									title: del_res.data.message,
									duration: 1000,
									success() {}

								})
							}
						}
					}
				})
			}



		},
		components: {
			loading,
			empty
		},

		computed: {
			day(){
				let day_num='';
				let start_times=(new Date(this.detail.datainfo.begin_time)).getTime()/1000;
				let end_times=(new Date(this.detail.datainfo.end_time)).getTime()/1000;
				day_num=(end_times-start_times)/(24*60*60)+1;
				return day_num;
			}
		},
		watch: {

		}

	}
</script>

<style lang="less" scoped>
	.detail-wrap {
		padding-bottom: 20rpx;

		.title {
			display: flex;
			align-items: center;
			padding: 30rpx 30rpx 0;
			font-size: 30rpx;

			image {
				width: 30rpx;
				margin-left: 20rpx;
			}
		}
	}

	.radio-group {
		display: flex;
		border-bottom: 1rpx solid #eee;

		.check-item {
			border-bottom: 0 none;
		}
	}


	.hd-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}
</style>
